package com.ckjava.test.service;

import com.ckjava.test.aop.annotation.AutoLog;
import com.ckjava.test.entity.UserEntity;
import com.ckjava.test.runner.UserRunner;
import org.springframework.stereotype.Service;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;


@Service
public class UserService {

    @AutoLog
    public UserEntity getUser(String name) {

        checkName(name);

        return new UserEntity("1", name);
    }

    public UserEntity getUserAsync(String name) throws Exception {

        checkName(name);

        ForkJoinTask<UserEntity> task = ForkJoinPool.commonPool().submit(new UserRunner(name));
        return task.get();
    }

    @AutoLog
    public boolean checkName(String name) {
        return true;
    }
}
